package com.yyk.yykywd.mvvm.ui

import androidx.databinding.DataBindingUtil
import androidx.lifecycle.Observer
import com.gyf.immersionbar.ImmersionBar
import com.yyk.yykywd.R
import com.yyk.yykywd.base.NewBaseActivity
import com.yyk.yykywd.databinding.ActivityModifyPwdBinding
import com.yyk.yykywd.getViewModel
import com.yyk.yykywd.mvvm.view_model.ModifyPwdViewModel
import com.yyk.yykywd.util.ToastUtil
import kotlinx.android.synthetic.main.rl_bottom.*
import kotlinx.android.synthetic.main.title.*

class ModifyPwdActivity : NewBaseActivity() {
    private val viewModel by lazy {
        getViewModel(this, ModifyPwdViewModel::class.java)
    }

    override fun initView() {
        val binding: ActivityModifyPwdBinding = DataBindingUtil.setContentView(this,
                R.layout.activity_modify_pwd)
        binding.viewModel = viewModel
        binding.lifecycleOwner = this

        tv_title.text = "修改登录密码"
        iv_back.setOnClickListener {
            finish()
        }

        tv_execute.text = "保存"
    }

    override fun initImmersionBar() {
        ImmersionBar.with(this)
                .statusBarDarkFont(true)
                .statusBarColor(R.color.white).init()
    }


    override fun setListener() {
        tv_execute.setOnClickListener {
            viewModel.modifyPwd()
        }

        viewModel.modifyPwd.observe(this, Observer {
            if (it.code == 200) {
                finish()
            }
            ToastUtil.showShort(it.msg)
        })
    }
}
